package com.emergency.examine.controller;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.examine.domain.Exam;
import com.emergency.examine.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/exam")
@Api(value = "考试类", tags = "记录考试信息")
public class ExamController {
    @Autowired
    private ExamService examService;

    @ApiOperation(value = "考试接口", notes = "生成考试信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "考试名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "考试类型", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "starttime", value = "开始时间", required = true, paramType = "query", dataType = "Date"),
            @ApiImplicitParam(name = "endtime", value = "结束时间", required = true, paramType = "query", dataType = "Date")
    })
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public Result save(@RequestBody Exam exam) {
        String id = examService.save(exam);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    @ApiOperation(value = "考试查询接口", notes = "查询考试信息")
    @RequestMapping(value = "get/{examId}", method = RequestMethod.GET)
    public Result get(@PathVariable("examId") Long examId) {
        Exam exam = examService.getInfo(examId);
        return new Result(true, StatusCode.OK, "操作成功", exam);
    }

    @ApiOperation(value = "考试列表获取接口", notes = "考试列表")
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<Exam> pageList = examService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

    @ApiOperation(value = "删除考试信息接口", notes = "删除考试信息")
    @RequestMapping(value = "del/{examId}", method = RequestMethod.POST)
    public Result del(@PathVariable("examId") Long examId) {
        examService.del(examId);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
